package com.owen.springboot.smartparkingms.module.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.owen.springboot.smartparkingms.common.model.Result;
import com.owen.springboot.smartparkingms.module.sys.entity.SysUser;
import com.owen.springboot.smartparkingms.module.sys.mapper.SysUserMapper;
import com.owen.springboot.smartparkingms.module.sys.service.ISysUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 系统用户 服务实现类
 * </p>
 *
 * @author Owen
 * @since 2022-02-25
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements ISysUserService {

    @Resource
    private SysUserMapper sysuserMapper;

    @Override
    public List<String> listUserRoles(Long userId) {
        return sysuserMapper.listUserRoles(userId);
    }

    @Override
    public List<String> listUserPerms(Long userId) {
        return sysuserMapper.listUserPerms(userId);
    }

    @Override
    public SysUser getUser(String username) {
        QueryWrapper query = new QueryWrapper<>()
                .eq("username",username);
        return sysuserMapper.selectOne(query);
    }

    @Override
    public Result listPage(SysUser user) {
        IPage<SysUser> page = new Page(user.getPageNo(),user.getPageSize());
        QueryWrapper query = new QueryWrapper<>()
                .like("username ",user.getDescription())
                .or().like("nickname ",user.getDescription());
        IPage<SysUser> list = sysuserMapper.selectPage(page,query);
        return Result.ok(list);
    }

    @Override
    public Result deleteById(Long userId) {
        sysuserMapper.deleteById(userId);
        return Result.ok("删除成功");
    }
}
